package com.appistry.maven.plugin.far.remote.ssh;

import com.jcraft.jsch.UIKeyboardInteractive;
import com.jcraft.jsch.UserInfo;

/**
 * <code>SshUserInfo</code> holds authentication information needed to connect
 * to the remote host
 * 
 * @see com.jcraft.jsch.UserInfo
 * 
 */
public class SshUserInfo implements UserInfo, UIKeyboardInteractive {

	private String username;
	private String password;

	private String keyFile;
	private String passphrase;

	private boolean trustCertificate;

	public SshUserInfo() {
		super();
	}

	public SshUserInfo(boolean trustCertificate) {
		super();
		this.trustCertificate = trustCertificate;
	}

	public SshUserInfo(String username, String password,
			boolean trustCertificate) {
		this.username = username;
		this.password = password;
		this.trustCertificate = trustCertificate;
	}

	public String getPassphrase() {
		return passphrase;
	}

	public String getPassword() {
		return password;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public boolean isTrustCertificate() {
		return trustCertificate;
	}

	public void setTrustCertificate(boolean trustCertificate) {
		this.trustCertificate = trustCertificate;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setPassphrase(String passphrase) {
		this.passphrase = passphrase;
	}

	public String getKeyFile() {
		return keyFile;
	}

	public void setKeyFile(String keyFile) {
		this.keyFile = keyFile;
	}

	public boolean promptPassphrase(String message) {
		System.out.println("SshUserInfo.promptPassphrase message: " + message);

		return true;
	}

	public boolean promptPassword(String message) {
		System.out.println("SshUserInfo.promptPassword: " + message);

		return true;
	}

	public boolean promptYesNo(String message) {
		// I believe this is the message returned by a remote unknown host when
		// you attempt to connect to it the first time (RSA key something....).
		// Ignore the message for now
		System.out.println("SshUserInfo.promptYesNo message: " + message);

		return trustCertificate;
	}

	public void showMessage(String message) {
		System.out.println("SshUserInfo.showMessage: " + message);
	}

	public String[] promptKeyboardInteractive(String destination, String name,
			String instruction, String[] prompt, boolean[] echo) {

		// TODO: Don't really know when this is invoked. Therefore will need to
		// review this when I run across it.
		// Returning null for now

		System.out
				.println("SshUserInfo.promptKeyboardInteractive destination: "
						+ destination);
		System.out.println("SshUserInfo.promptKeyboardInteractive name: "
				+ name);
		System.out
				.println("SshUserInfo.promptKeyboardInteractive instruction: "
						+ instruction);
		System.out.println("SshUserInfo.promptKeyboardInteractive prompt: "
				+ prompt);
		System.out.println("SshUserInfo.promptKeyboardInteractive echo: "
				+ echo);

		return null;
	}

}
